package com.ebuy.api.base.dto;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

@Getter
@Setter
public class BaseResp implements Serializable {

    // 定义jackson对象

    // 状态码
    private String code;

    // 响应消息
    private String msg;

    // 响应中的数据
    private Object data;
    // 通用状态码
    public static String SUCCESS = "1";
    public static String FAIL = "0";
    public static String NO_AUTH = "-999";

    public static BaseResp build(String status, String msg, Object data) {
        return new BaseResp(status, msg, data);
    }

    public static BaseResp success(Object data) {
        return new BaseResp(data);
    }

    public static BaseResp success(String msg, Object data) {
        return build(SUCCESS, msg, data);
    }

    public static BaseResp success() {
        return new BaseResp(null);
    }

    public static BaseResp fail(String msg, Object data) {
        return build(FAIL, msg, data);
    }

    public static BaseResp fail(String msg) {
        return build(FAIL, msg, null);
    }

    private BaseResp() {

    }

    public BaseResp(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private BaseResp(Object data) {
        this.code = SUCCESS;
        this.msg = "操作成功";
        this.data = data;
    }

    public BaseResp(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }


}
